﻿@model IEnumerable<General.Entities.SysRole>
@{
    ViewData["Title"] = "角色列表";
    bool canAddOrUpdate =  WorkContext.OwnPermission("editRole");
    bool canPermission = WorkContext.OwnPermission("rolePermission");
    bool canDelete = WorkContext.OwnPermission("deleteUser");
}

<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="@Url.RouteUrl("mainIndex")">首页</a>
        </li>
        <li class="active">@ViewBag.Title</li>
    </ul>
</div>
<div class="page-content">
    <h1>@ViewBag.Title</h1>
    <hr />
    <div class="row">
        <div class="col-sm-12">
            <a asp-route="editRole" class = "btn btn-sm btn-pink btnEditRole"><i class="glyphicon glyphicon-plus"></i>添加角色</a>
        </div>
    </div>
    <div class="space-2"></div>
    @if (Model != null)
    {
        int i = 1;
        <div class="row">
            <div class="col-sm-12">
                <table id="user_datatable" class="table table-striped table-bordered table-hover dataTable no-footer">
                    <thead>
                        <tr>
                            <th width="100px"></th>
                            <th width="300px">名称</th>
                            <th width="200px">时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model)
                        { 
                            <tr>
                                <td>@(i++)</td>
                                <td>@item.Name</td>
                                <td>@item.CreationTime.ToString("F")</td>
                                <td> 
                                    @if (canAddOrUpdate)
                                    {
                                        <a href="@Url.RouteUrl("editRole", new { id = item.Id })" class="btn btn-xs btn-primary btnEditRole"><i class="glyphicon glyphicon-pencil"></i></a>
                                    }
                                    @if (canDelete)
                                    {
                                        <a href="@Url.RouteUrl("deleteRole", new { id = item.Id })" class="btn btn-xs btn-danger btnDelete"><i class="glyphicon glyphicon-trash"></i></a>
                                    }
                                    @if (canPermission)
                                    {
                                        <a href="@Url.RouteUrl("rolePermission", new { id = item.Id })"class = "btn btn-xs btn-purple"><i class="fa fa-bolt"></i>设置权限</a>
                                    }
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
            <script>
                $(function () {
                     
                    $('.btnEditRole').click(function (e) {
                        e.preventDefault();
                        var _url = this.href;
                        layer.load(2);
                        $.get(_url, function (html) {
                            layer.closeAll();
                            layer.open({
                                type: 1,
                                title: '编辑角色',
                                area: ['500px', '300px'],
                                content: html
                            });
                        });

                    });
                    $('.btnDelete').click(function (e) {
                        e.preventDefault();
                        var url = this.href;
                        layer.confirm('删除后将不可恢复，您确定要删除此角色？', {
                            btn: ['确定', '取消'] //按钮
                        }, function () {
                            layer.load(2);
                            $.get(url, function (data) {
                                if (data.Status) {
                                    location.reload();
                                } else {
                                    layer.msg(data.Message, { icon: 2 });
                                }
                            });
                        });
                    });


                });
            </script>
    }
</div>






